import i18n from '@/locales'

const { t } = i18n.global

export const taskStatus = {
  success: {
    code: 200,
    label: t('osManager.success'),
    field: 'success',
  },
  notExecuted: {
    code: 201,
    label: t('osManager.ready'),
    field: 'notExecuted',
  },
  executing: {
    code: 202,
    label: t('osManager.executing'),
    field: 'executing',
  },
  pause: {
    code: 203,
    label: t('osManager.pause'),
    field: 'pause',
  },
  canceled: {
    code: 204,
    label: t('osManager.canceled'),
    field: 'canceled',
  },
  partSuccess: {
    code: 206,
    label: t('osManager.partSuccess'),
    field: 'partSuccess',
  },
  timeout: {
    code: 207,
    label: t('osManager.timeout'),
    field: 'timeout',
  },
  waiting: {
    code: 208,
    label: t('osManager.wait'),
    field: 'waiting',
  },
  dataFail: {
    code: 209,
    label: t('osManager.reportDataFail'),
    field: 'dataFail',
  },
  fail: {
    code: 400,
    label: t('osManager.fail'),
    field: 'fail',
  },
  revocerable: {
    code: 402,
    label: t('osManager.tobeHarden'),
    field: 'recoverable',
  },
  exception: {
    code: 600,
    label: t('osManager.abnormal'),
    field: 'exception',
  },
};

export function getStatus(code) {
  for (let i = 0; i < Object.keys(taskStatus).length; i++) {
    const status = Object.keys(taskStatus)[i];
    if (taskStatus[status].code === Number(code)) {
      return taskStatus[status];
    }
  }
  return '';
}
